using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using Sedna.Core.Controller;
using Sedna.Core.Controller.Common;

namespace Sedna.Core.Controls.Actions
{
    public class ChainAction : AbstractAction
    {
        private IList chain;
        private String resultsPath;


        # region Propeties
        
        /// <summary>
        /// Chain of actions <see cref="IAction"/> that must be executed
        /// </summary>
        public IList Chain
        {
            set { chain = value; }
        }

        /// <summary>
        /// A path to set list of <see cref="IActionResult"/>
        /// </summary>
        public string ResultsPath
        {
            set { resultsPath = value; }
        }

        # endregion

        public override IActionResult Execute(IExecutionContext executionContext)
        {
            IList results = new ArrayList();
            
            if (chain != null)
            {
                foreach (IAction action in chain)
                {
                    results.Add(action.Execute(executionContext));
                }
            }
            
            if (!String.IsNullOrEmpty(resultsPath))
                executionContext.SetPropertyValue(resultsPath, results);

            return CreateResult(successStatus);
        }
    }
}
